function [F1, F11, F2, F22, F3, F4] = GAD_Etom_Cross_Day_ER_DeltaT(XDay_ER_Summary)
%% get cross-day ER vs deltaT for G17

T1 = {'2020-07-21';'2020-07-23';'2020-07-28';'2020-07-30';'2020-08-04';'2020-08-13';'2020-08-18';'2020-08-20';'2020-08-27';'2020-09-01';'2020-09-10';'2020-09-17';'2020-09-24'};
T1 = datetime(T1,'InputFormat','yyyy-MM-dd');

Comb_Pair = nchoosek((1:size(T1,1)),2);

for n = 1:size(Comb_Pair,1)
    deltaT1(n,1) = daysact(T1(Comb_Pair(n,1),1),T1(Comb_Pair(n,2),1));
end

ER1 (:,1) = extractfield(XDay_ER_Summary.G2_F4_17, 'ER_Corr_Values');


%% get cross-day ER vs deltaT for G18

T2 = {'2020-07-21';'2020-07-23';'2020-07-28';'2020-07-30';'2020-08-04';'2020-08-13';'2020-08-18';'2020-08-20';'2020-08-27';'2020-09-01';'2020-09-10';'2020-09-17';'2020-09-24'};
T2 = datetime(T2,'InputFormat','yyyy-MM-dd');

Comb_Pair = nchoosek((1:size(T2,1)),2);

for n = 1:size(Comb_Pair,1)
    deltaT2(n,1) = daysact(T2(Comb_Pair(n,1),1),T2(Comb_Pair(n,2),1));
end

ER2 (:,1) = extractfield(XDay_ER_Summary.G2_F4_18, 'ER_Corr_Values');


%% get cross-day ER vs deltaT for G21

T3 = {'2020-12-29';'2021-01-05';'2021-01-07';'2021-01-14';'2021-01-26';'2021-01-29';'2021-02-02';'2021-02-09';'2021-02-11';'2021-02-16';'2021-02-19';'2021-02-23';'2021-02-25';'2021-03-02';'2021-03-04';'2021-03-24'};
T3 = datetime(T3,'InputFormat','yyyy-MM-dd');

Comb_Pair = nchoosek((1:size(T3,1)),2);

for n = 1:size(Comb_Pair,1)
    deltaT3(n,1) = daysact(T3(Comb_Pair(n,1),1),T3(Comb_Pair(n,2),1));
end

ER3 (:,1) = extractfield(XDay_ER_Summary.G2_F52_21, 'ER_Corr_Values');

%% get cross-day ER vs deltaT for G28

T4 = {'2020-12-29';'2021-01-05';'2021-01-07';'2021-01-14';'2021-01-26';'2021-01-29';'2021-02-02';'2021-02-09';'2021-02-11';'2021-02-16';'2021-02-19';'2021-02-23';'2021-02-25';'2021-03-02';'2021-03-04';'2021-03-24'};
T4 = datetime(T4,'InputFormat','yyyy-MM-dd');

Comb_Pair = nchoosek((1:size(T4,1)),2);

for n = 1:size(Comb_Pair,1)
    deltaT4(n,1) = daysact(T4(Comb_Pair(n,1),1),T4(Comb_Pair(n,2),1));
end

ER4 (:,1) = extractfield(XDay_ER_Summary.G2_F52_28, 'ER_Corr_Values');

%% get cross-day ER vs deltaT for G31

T5 = {'2021-02-09';'2021-02-11';'2021-02-16';'2021-02-19';'2021-02-23';'2021-02-25';'2021-03-02';'2021-03-04';'2021-03-18';'2021-03-22';'2021-03-24';'2021-03-26'};
T5 = datetime(T5,'InputFormat','yyyy-MM-dd');

Comb_Pair = nchoosek((1:size(T5,1)),2);

for n = 1:size(Comb_Pair,1)
    deltaT5(n,1) = daysact(T5(Comb_Pair(n,1),1),T5(Comb_Pair(n,2),1));
end

ER5 (:,1) = extractfield(XDay_ER_Summary.G2_F52_31, 'ER_Corr_Values');

%% get cross-day ER vs deltaT for G34

T6 = {'2021-02-02';'2021-02-09';'2021-02-11';'2021-02-16';'2021-02-19';'2021-02-23';'2021-02-25';'2021-03-02';'2021-03-04';'2021-03-18';'2021-03-22';'2021-03-24';'2021-03-26'};
T6 = datetime(T6,'InputFormat','yyyy-MM-dd');

Comb_Pair = nchoosek((1:size(T6,1)),2);

for n = 1:size(Comb_Pair,1)
    deltaT6(n,1) = daysact(T6(Comb_Pair(n,1),1),T6(Comb_Pair(n,2),1));
end

ER6 (:,1) = extractfield(XDay_ER_Summary.G2_F52_34, 'ER_Corr_Values');

%% get cross-day ER vs deltaT for G45

T7 = {'2021-03-29';'2021-03-31';'2021-04-05';'2021-04-07';'2021-04-12';'2021-04-14';'2021-04-16';'2021-04-19';'2021-04-21';'2021-04-23';'2021-04-26';'2021-04-28';'2021-04-30'};
T7 = datetime(T7,'InputFormat','yyyy-MM-dd');

Comb_Pair = nchoosek((1:size(T7,1)),2);

for n = 1:size(Comb_Pair,1)
    deltaT7(n,1) = daysact(T7(Comb_Pair(n,1),1),T7(Comb_Pair(n,2),1));
end

ER7 (:,1) = extractfield(XDay_ER_Summary.G2_F52_45, 'ER_Corr_Values');

%% get cross-day ER vs deltaT for G53

T8 = {'2021-03-29';'2021-03-31';'2021-04-05';'2021-04-07';'2021-04-12';'2021-04-14';'2021-04-16';'2021-04-19';'2021-04-21';'2021-04-23';'2021-04-26';'2021-04-28';'2021-04-30'};
T8 = datetime(T8,'InputFormat','yyyy-MM-dd');

Comb_Pair = nchoosek((1:size(T8,1)),2);

for n = 1:size(Comb_Pair,1)
    deltaT8(n,1) = daysact(T8(Comb_Pair(n,1),1),T8(Comb_Pair(n,2),1));
end

ER8 (:,1) = extractfield(XDay_ER_Summary.G2_F52_53, 'ER_Corr_Values');

%% linear regression

T_WT = cat(1,deltaT2,deltaT4,deltaT5,deltaT6);
ER_WT = cat(1,ER2,ER4,ER5,ER6);

T_MUT = cat(1,deltaT1,deltaT3,deltaT7,deltaT8);
ER_MUT = cat(1,ER1,ER3,ER7,ER8);

figure
subplot(1,2,1)
F1 = fit(T_WT,ER_WT,'poly1');
plot(F1,T_WT,ER_WT,'ob');
xlabel('deltaT (days)')
ylabel('mean(ER correlation)')
set(gca, 'FontSize', 20)
title('p-WT', 'FontSize', 25)
ylim([-0.8,1])
xlim([0,90])
legend('off')

subplot(1,2,2)
F2 = fit(T_MUT,ER_MUT,'poly1');
plot(F2,T_MUT,ER_MUT,'ob');
xlabel('deltaT (days)')
ylabel('mean(ER correlation)')
set(gca, 'FontSize', 20)
title('\alpha5-i-KO', 'FontSize', 25)
ylim([-0.8,1])
xlim([0,90])
legend('off')

F11 = fitlm(T_WT,ER_WT);
F22 = fitlm(T_MUT,ER_MUT);

%% Alternatively, exponential regression

figure
subplot(1,2,1)
F3 = fit(T_WT,ER_WT,'exp1');
plot(F3,T_WT,ER_WT,'^b');
xlabel('deltaT (days)')
ylabel('mean(ER correlation)')
set(gca, 'FontSize', 20)
title('p-WT', 'FontSize', 25)
ylim([-0.8,1])
xlim([0,90])
legend('off')

subplot(1,2,2)
F4 = fit(T_MUT,ER_MUT,'exp1');
plot(F4,T_MUT,ER_MUT,'^b');
xlabel('deltaT (days)')
ylabel('mean(ER correlation)')
set(gca, 'FontSize', 20)
title('\alpha5-i-KO', 'FontSize', 25)
ylim([-0.8,1])
xlim([0,90])
legend('off')

end